package net.oschina.dajiangnan.wx.process.mp;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import net.oschina.dajiangnan.wx.process.mp.tools.SignatureValid;


public class Echo {

    private static Logger logger = Logger.getLogger(Echo.class);
    
    public String process(HttpServletRequest req) throws Exception{
        
        String signature = req.getParameter("signature");
        String echostr = req.getParameter("echostr");
        String timestamp = req.getParameter("timestamp");
        String nonce = req.getParameter("nonce");

        if(SignatureValid.valid(signature,timestamp,nonce)){
            logger.debug("echo SUCESS");
            return echostr;
        }else{
            logger.debug("echo FAIL , signature = " + signature + " , echostr = " + echostr +" , timestamp = " + timestamp +" , nonce = " + nonce);
            return "";
        }
    }
}
